import request from '@/utils/request.ts'
import type { CategoryResponseData, AttrResponseData, AttrObj } from './type.ts'
//属性管理接口
enum API {
  //获取一级分类
  GET_CATEGORY1 = '/admin/product/getCategory1',
  //获取二级分类
  GET_CATEGORY2 = '/admin/product/getCategory2',
  //获取三级分类
  GET_CATEGORY3 = '/admin/product/getCategory3',
  //保存属性
  SAVE_ATTR = '/admin/product/saveAttrInfo',
  //删除基础属性
  DELETE_ATTR = '/admin/deleteAttr',
  //获取分类下已有的属性与属性值
  GET_ATTR = '/admin/product/attrInfoList',
}

export const reqCategory1 = () =>
  request.get<any, CategoryResponseData>(API.GET_CATEGORY1)
export const reqCategory2 = (category1Id: number | string) =>
  request.get<any, CategoryResponseData>(API.GET_CATEGORY2 + `/${category1Id}`)
export const reqCategory3 = (category2Id: number | string) =>
  request.get<any, CategoryResponseData>(API.GET_CATEGORY3 + `/${category2Id}`)

//保存属性
export const reqSaveAttr = (data: AttrObj) =>
  request.post<any, any>(API.SAVE_ATTR, data)

//删除属性
export const reqDeleteAttr = (attrId: number) =>
  request.delete<any, any>(API.DELETE_ATTR + `/${attrId}`)

//获取分类下已有的属性与属性值
export const reqGetAttr = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string,
) =>
  request.get<any, AttrResponseData>(
    API.GET_ATTR + `/${category1Id}/${category2Id}/${category3Id}`,
  )
